package routers

import (
	"blog_go/global"
	"blog_go/middleware"
	"blog_go/routers/admin_router"
	router2 "blog_go/routers/front_router"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	gs "github.com/swaggo/gin-swagger"
	"net/http"
)

func InitRouters() *gin.Engine {
	gin.SetMode(global.Conf.System.Env)
	router := gin.Default()
	// 设置静态资源路劲
	router.StaticFS("uploads", http.Dir("uploads"))
	// 添加中间键 1异常拦截 2链路跟踪
	router.Use(middleware.ErrorHandle)
	// swag配置
	router.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))
	baseGroup := router.Group("/api")
	admin_router.InitAdminRouter(baseGroup)
	router2.InitRouter(baseGroup)
	return router
}
